#

class Cifar100Text(object):
    def __init__(self):
        self.name = 'apps.clip.cifar100_text.Cifar100Text'

    @staticmethod
    def load_cifar100_texts() -> None:
        '''
        生成类别对应的说明文字：
            类别编号：超类名,类名
        分为中文和英文两套
        '''
        cifar100_classes_txt = 'apps/clip/cifar100_classes.txt'
        cifar100_super_classes_txt = 'apps/clip/cifar100_super_classes.txt'
        cls_zh_dict = {} # class_id: text(super_classname,classname)
        cls_en_dict = {}
        with open(cifar100_classes_txt, 'r', encoding='utf-8') as rfd:
            for row in rfd:
                row = row.strip()
                arrs0 = row.split(',')
                cls_zh_dict[int(arrs0[0])] = arrs0[1]
                cls_en_dict[int(arrs0[0])] = arrs0[2]
        mm_text_en = {} # cls_id: super-classname, classname
        mm_text_zh = {} # cls_id: super-classname, classname
        with open(cifar100_super_classes_txt, 'r', encoding='utf-8') as rfd:
            for row in rfd:
                row = row.strip()
                arrs0 = row.split('|')
                super_classname_zh = arrs0[0]
                super_classname_en = arrs0[1]
                cls_ids = arrs0[2].split(',')
                cls_ens = arrs0[3].split(',')
                for idx in range(len(cls_ids)):
                    mm_text_en[int(cls_ids[idx])] = f'{super_classname_en},{cls_ens[idx]}'
                    mm_text_zh[int(cls_ids[idx])] = f'{super_classname_zh},{cls_zh_dict[int(cls_ids[idx])]}'
        return mm_text_en, mm_text_zh